﻿using FDEEPublicFunc;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FDEEMain
{
    public partial class BufferStructureForm : Form
    {
        public string filePlinthName = "";
        public string fileBeamParaName = "";
        public FDEE.Model.eSubType eHeightType = FDEE.Model.eSubType.None;
        public string piersString = "";
        public string IAParas = "";
        public string IBParas = "";
        public string TAParas = "";
        public string TBParas = "";
        public string title = "";
        public int stNum = 0;
        public int endNum = 0;
        public bool isPositive = false;
        public BufferStructureForm()
        {
            InitializeComponent();           
        }
      

        private void btnConfim_Click(object sender, EventArgs e)
        {
            title = cbLine.Text;

            if (string.IsNullOrWhiteSpace(filePlinthName))
            {
                MessageBox.Show("请选择垫石坐标表！", "提示");
                return;
            }
            if (string.IsNullOrWhiteSpace(fileBeamParaName))
            {
                //MessageBox.Show("请选择盖梁垫石参数表！", "提示");
                //return;
            }
            //piersString = pierList.Text;
             IAParas = IPara.Text;
            IBParas = iBPara.Text;
            TAParas = TPara.Text;
            TBParas = TBPara.Text;
            stNum = int.Parse(stNo.Text);
            endNum = int.Parse(endNo.Text);
            this.DialogResult = DialogResult.OK;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            //打开文件
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.DefaultExt = "xlsx";
            dlg.Filter = "xlsx Files|*.xlsx";
            if (dlg.ShowDialog() == DialogResult.OK)
                fileBeamParaName = dlg.FileName;
            if (fileBeamParaName == null)
                return;
            tkPath.Text = fileBeamParaName;// new System.IO.FileInfo(fileName).Name;
            System.IO.FileInfo file = new System.IO.FileInfo(fileBeamParaName);
            System.Data.DataTable dt;
            if (file.Extension.Contains("xlsx"))
                dt = new FDEECommonTools.ExcelHelper().ExcelToTableForXLSX(fileBeamParaName);
            else
                dt = FDEECommonTools.CVSTools.OpenCSV(fileBeamParaName);
            if(dt.Rows.Count>0)
            {
                stNo.Items.Clear();
                endNo.Items.Clear();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    stNo.Items.Add(i);
                    endNo.Items.Add(i);
                }
                stNo.SelectedIndex = 0;
                endNo.SelectedIndex = dt.Rows.Count - 1;
            }
        }

        private void btnPlinth_Click(object sender, EventArgs e)
        {
            //打开文件
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.DefaultExt = "csv";
            dlg.Filter = "csv Files|*.csv";
            if (dlg.ShowDialog() == DialogResult.OK)
                filePlinthName = dlg.FileName;
            if (filePlinthName == null)
                return;
            plinthPath.Text = filePlinthName;// new System.IO.FileInfo(fileName).Name;
        }

        private void ck_CheckedChanged(object sender, EventArgs e)
        {
            if (ck.Checked)
                isPositive = true;
            else
                isPositive = false;
        }
    }
}
